package com.bjh.util;

import com.bjh.system.response.Resp;
import org.slf4j.Logger;

import java.util.Map;

public class BaseController {
    /**
     * 用于计算接口的响应时间（多线程时除外）
     */
    private static long startTime = 0;
    private static long endTime = 0;

    public static void logBefore(Logger logger, String interfaceName){
        logger.info("");
        logger.info("++++++++++  start  ++++++++++");
        logger.info(interfaceName);
        startTime = System.currentTimeMillis();
    }
    public static void logAfter(Logger logger){
        endTime = System.currentTimeMillis();
        logger.info("++++++++++   "+ (endTime - startTime) +"毫秒   ++++++++++");
        logger.info("++++++++++   end   ++++++++++");
        logger.info("");
    }
    /**
     * 返回带数据的成功结果
     * @param object 返回数据
     * @return {@link Map}
     */
    public static Map<String, Object> returnSuccessWithData(Object object){
        return Resp.getInstance(0,"ok",object);
    }
    /**
     * 返回成功结果
     * @return {@link Map}
     */
    public static Map<String, Object> returnSuccess(){
        return Resp.getInstance(0,"ok",null);
    }
    /**
     * 返回自定义结果
     * @param code 返回码
     * @param msg 返回信息
     * @param object 返回数据
     * @return {@link Map}
     */
    public static Map<String, Object> returnResult(int code,String msg,Object object){
        return Resp.getInstance(code,msg,object);
    }
    /**
     * 返回自定义结果
     * @param code 返回码
     * @param msg 返回信息
     * @return {@link Map}
     */
    public static Map<String, Object> returnResult(int code,String msg){
        return Resp.getInstance(code,msg,null);
    }
    /**
     * 获取请求参数
     * @param request request
     * @return {@link Map}
     */
}
